<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>教材列表</title>
    <link rel="stylesheet" href="/element-ui/index.css">
    <link rel="stylesheet" href="/element-ui/fonts/element-icons.css">
    <script src="/element-ui/vue.js"></script>
    <script src="/element-ui/index.js"></script>
    <script src="/element-ui/axios.min.js"></script>
    <style>
        body {
            font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '\\5FAE\\8F6F\\96C5\\9ED1', Arial, sans-serif;
            background-color: #f5f6fa;
        }
        #app {
            padding: 20px;
            background-color: #f5f6fa;
        }
        .page-title {
            font-size: 26px;
            font-weight: bold;
            color: #333;
            background: #fff;
            padding: 24px 20px 12px 20px;
            border-bottom: 1px solid #eee;
            margin-bottom: 20px;
            letter-spacing: 2px;
            text-align: center;
            animation: fadeInDown 0.8s ease-out;
            box-shadow: 0 2px 8px rgba(0,0,0,0.05);
            border-radius: 8px;
        }
        @keyframes fadeInDown {
            from { opacity: 0; transform: translateY(-20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .el-main {
            padding: 20px;
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.05);
        }
        .el-form-item {
            margin-bottom: 20px;
        }
        .el-input__inner,
        .el-select .el-input__inner {
            transition: all 0.3s ease;
        }
        .el-input__inner:focus,
        .el-input__inner:hover,
        .el-select .el-input__inner:focus,
        .el-select .el-input__inner:hover {
            border-color: #409EFF;
            box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
        }
        .el-button {
            transition: all 0.3s ease;
        }
        .el-button:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 10px rgba(64, 158, 255, 0.2);
        }
        .el-button--primary:hover {
            box-shadow: 0 4px 10px rgba(64, 158, 255, 0.2);
        }
        .el-button--success:hover {
            box-shadow: 0 4px 10px rgba(103, 194, 58, 0.2);
        }

        .el-table {
            animation: fadeIn 1s ease-out;
        }
        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }
        .el-table__row {
            transition: all 0.3s ease;
        }
        .el-table__row:hover {
            background-color: #f5f7fa !important;
            transform: scale(1.005);
            box-shadow: 0 2px 8px rgba(0,0,0,0.05);
        }
        .pagination-container {
            margin-top: 20px;
            text-align: right;
            padding: 10px 0;
            background: #fff;
            border-top: 1px solid #eee;
            border-radius: 0 0 8px 8px;
        }
        .el-pagination button,
        .el-pagination .btn-prev,
        .el-pagination .btn-next,
        .el-pagination .el-pager li {
            transition: all 0.3s ease;
        }
        .el-pagination button:hover,
        .el-pagination .btn-prev:hover,
        .el-pagination .btn-next:hover,
        .el-pagination .el-pager li:hover {
            color: #409EFF;
            transform: translateY(-1px);
        }
        .action-btn-group {
            display: flex;
            gap: 8px;
            flex-wrap: nowrap;
            align-items: center;
        }
        .action-btn-group .el-button {
            font-size: 13px;
            min-width: 56px;
            padding: 7px 12px;
        }
    </style>
</head>
<body>
    <div class="page-title">教材管理</div>
    <div id="app">
        <el-container>
            <el-main>
                <!-- 搜索表单 -->
                <el-form :inline="true" :model="searchForm" class="demo-form-inline">
                    <el-form-item label="教材名称">
                        <el-input v-model="searchForm.name" placeholder="请输入教材名称"></el-input>
                    </el-form-item>
                    <el-form-item label="ISBN">
                        <el-input v-model="searchForm.isbn" placeholder="请输入ISBN"></el-input>
                    </el-form-item>
                    <el-form-item label="作者">
                        <el-input v-model="searchForm.author" placeholder="请输入作者"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="search">查询</el-button>
                        <el-button @click="resetForm">重置</el-button>
                        <el-button type="success" @click="add">新增</el-button>
                    </el-form-item>
                </el-form>

                <!-- 数据表格 -->
                <el-table :data="tableData" border style="width: 100%" v-loading="loading">
                    <el-table-column prop="isbn" label="ISBN" width="180"></el-table-column>
                    <el-table-column prop="name" label="教材名称" width="180"></el-table-column>
                    <el-table-column prop="author" label="作者"></el-table-column>
                    <el-table-column prop="publisher.name" label="出版社"></el-table-column>
                    <el-table-column prop="price" label="价格"></el-table-column>
                    <el-table-column prop="publishDate" label="出版日期"></el-table-column>
                    <el-table-column label="操作" width="260">
                        <template slot-scope="scope">
                            <div class="action-btn-group">
                                <el-button size="mini" @click="handleEdit(scope.row)">编辑</el-button>
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                                <el-button size="mini" type="info" @click="handleDetail(scope.row)">详情</el-button>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>

                <!-- 分页 -->
                <div class="pagination-container">
                    <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="currentPage"
                        :page-sizes="[10, 20, 30, 50]"
                        :page-size="pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                    </el-pagination>
                </div>
            </el-main>
        </el-container>
    </div>

    <script>
        new Vue({
            el: '#app',
            data() {
                return {
                    searchForm: {
                        name: '',
                        isbn: '',
                        author: '',
                        publisherId: null
                    },
                    tableData: [],
                    currentPage: 1,
                    pageSize: 10,
                    total: 0,
                    loading: false
                }
            },
            created() {
                this.fetchData();
            },
            methods: {
                fetchData() {
                    this.loading = true;
                    const params = {
                        pageNum: this.currentPage,
                        pageSize: this.pageSize,
                        ...this.searchForm
                    };
                    axios.get('/book/api/list', { params })
                        .then(response => {
                            this.tableData = response.data.list;
                            this.total = response.data.total;
                        })
                        .catch(error => {
                            console.error('Error fetching data:', error);
                            this.$message.error('获取数据失败');
                        })
                        .finally(() => {
                            this.loading = false;
                        });
                },
                search() {
                    this.currentPage = 1;
                    this.fetchData();
                },
                resetForm() {
                    this.searchForm = {
                        name: '',
                        isbn: '',
                        author: '',
                        publisherId: null
                    };
                    this.search();
                },
                handleSizeChange(val) {
                    this.pageSize = val;
                    this.fetchData();
                },
                handleCurrentChange(val) {
                    this.currentPage = val;
                    this.fetchData();
                },
                add() {
                    window.location.href = '/book/add';
                },
                handleEdit(row) {
                    window.location.href = `/book/edit/${row.id}`;
                },
                handleDelete(row) {
                    this.$confirm('确认删除该教材?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        axios.post(`/book/delete/${row.id}`)
                            .then(response => {
                                if (response.data === 'success') {
                                    this.$message.success('删除成功');
                                    this.fetchData();
                                } else {
                                    this.$message.error('删除失败');
                                }
                            })
                            .catch(error => {
                                console.error('Error deleting book:', error);
                                this.$message.error('删除失败');
                            });
                    }).catch(() => {
                        this.$message.info('已取消删除');
                    });
                },
                handleDetail(row) {
                    window.location.href = `/book/detailPage/${row.id}`;
                }
            }
        });
    </script>
</body>
</html> 